/*
	Answer to Exercise 2-7, page 49
		Write a function invert(x,p,n) that returns x with the n bits that begin at position p 
	inverted (i.e., 1 changed into 0 and vice versa), leaving the others unchanged.
*/
#include  <stdlib.h>
int main(){
	int x = 052;//0,101,010
	int p = 0, n = 3;
	int obj;
	obj = invert(x, p, n);
	printf("%u\n", obj);
	return 0; 
} 

/*int invert(int x, int p, int n){
	return 	(~x>>p & ~(~0<<n));
}
*/

int invert(int x, int p, int n)
{
    return x ^ (~(~0U << n) << p);
}
